package vboot.core.module.mon.log.login;

import vboot.core.common.dao.JdbcDao;
import vboot.core.common.dao.Sqler;
import vboot.core.common.api.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("mon/log/login")
public class MonLogLoginApi {

    @GetMapping
    public R get(String name) {
        Sqler sqlHelper = new Sqler("t.*", "mon_log_login");
        sqlHelper.addLike("t.name", name);
        sqlHelper.addOrder("t.crtim desc");
        return R.ok(jdbcDao.findPageData(sqlHelper));
    }

    @GetMapping("one/{id}")
    public R getOne(@PathVariable String id) {
        return R.ok(repo.findById(id).get());
    }

    @DeleteMapping("{ids}")
    public R delete(@PathVariable String[] ids)  {
        for (String id : ids) {
            repo.deleteById(id);
        }
        return R.ok();
    }

    @DeleteMapping("all")
    public R deleteAll()  {
        repo.deleteAll();
        return R.ok();
    }

    @Autowired
    private JdbcDao jdbcDao;

    @Autowired
    private MonLogLoginRepo repo;
}
